<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>邮件管理</legend>
            <div style="margin: 10px">
            </div>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn"  lay-event="add" auth="package:add">新增</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>
<style>
    .layui-table-cell { /*自适应行高*/
        height: auto !important;
        white-space: normal;
    }
</style>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>

<script type="text/html" id="btns">
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="detail" auth="equipSend:detail">
        查看
    </button>
    {{# if(d.auth_status==0){ }}
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="auth" auth="equipSend:auth">
        通过审核
    </button>
    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="noauth" auth="equipSend:noauth">
        拒绝审核
    </button>
    {{# } }}
</script>

<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        table.render({

            elem: '#currentTableId',
            url: '/admin/equipSend/paginate',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'print' ],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id',  title: 'ID', sort: true},
                {field: 'title',title: '邮件'},
                {field: 'description', title: '描述'},
                {field:"game_area",title: '区服编码'},
                {field:"roleIdsStr",title: '接收者',width:220},
                {field: 'created_at', title: '创建时间',width:220},
                {field: 'sendStatusName', title: '发送状态'},
                {field: 'authStatusName', title: '审核状态'},
                {field:'auth_at',title:"审核时间",width:220},
                {field:'操作',width:300, templet: '#btns'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line',
        });
        var tableReload = function(){
            //执行搜索重载
            table.reload('currentTableId');
        }
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'add.html',
                });

            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var row = obj.data;
            if(obj.event==='auth'){
                layer.confirm('您确定通过吗?',{title:"提示"},function(){
                    $.post("/admin/equipSend/auth/"+obj.data.id,{_method:"put"},function(res){
                        if (res.code!=0){
                            layer.msg(res.msg,{icon:5})
                        }else {
                            layer.msg(res.msg,{icon:1})
                        }
                        tableReload()
                    })
                })
            } else if(obj.event==='noauth'){
                layer.confirm('您确定拒绝吗?',{title:"提示"},function(){
                    $.post("/admin/equipSend/noauth/"+obj.data.id,{_method:"put"},function(res){
                        if (res.code!=0){
                            layer.msg(res.msg,{icon:5})
                        }else {
                            layer.msg(res.msg,{icon:1})
                        }
                        tableReload()
                    })
                })
            } else if(obj.event==='detail'){
                var index = layer.open({
                    title: '查看详情',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['800px', '600px'],
                    content: 'detail.html?id='+obj.data.id,
                });
            }
        });
    });
</script>
</body>
</html>